#include <NewLife.h>
#include <stdio.h>
#include "Driver.h"

CDriver::CDriver()
{
	for(int i=0; i<IRP_COUNT; i++)
		handler[i] = (IRP_HANDLER)&CDriver::doDummy;

	RegisterIRQ();
	RegisterPort();
	MapMemory();
}
CDriver::~CDriver()
{
	UnRegisterIRQ();
	UnRegisterPort();
}

void CDriver::RegisterIRQ()
{
	::RegisterIRQ(IRQs_nr, IRQs);	
}

void CDriver::RegisterPort()
{
	::RegisterPort(ports_nr, ports);
}

void CDriver::UnRegisterIRQ()
{
	::UnRegisterIRQ(IRQs_nr, IRQs);
}

void CDriver::UnRegisterPort()
{
	::UnRegisterPort(ports_nr, ports);
}

void CDriver::MapMemory()
{
	if(bMapMemory)
		::MapAddress(vaddr, size, paddr);
}

bool CDriver::ProcessMessage(RequestPackage *IRP, int * ret)
{
	// Get IRP type
	int type = IRP->GetRequestType();
	
	// Get handler
	IRP_HANDLER fun = handler[type];

	if(fun==NULL)
		return true;

	// Do
	return (this->*fun)(IRP, ret);
}

